//
//  ActiveCollectionViewCell.m
//  Findif
//
//  Created by Cicel Chen on 2018/10/19.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "ActiveCollectionViewCell.h"


@interface ActiveCollectionViewCell ()

@property (nonatomic, weak)UILabel * titleLabel;

@end

@implementation ActiveCollectionViewCell


-(void)setModel:(CategoryModel *)model{
    
    _model = model;
    
    NSString * usrlStr = [NSString stringWithFormat:@"%@%@",BASEURLSTR,model.img];
    
    NSURL * url = [NSURL URLWithString:usrlStr];
    
    self.titleLabel.text = model.name;
//    [self.imageButton sd_setImageWithURL:url forState:UIControlStateNormal];
    [self.imageButton sd_setImageWithURL:url];
}

-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        //设置控件
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
//    FFF2B6
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeButtonState) name:@"changeButtonState" object:nil];
    
    UIView * backView = [UIView new];
    
    backView.backgroundColor = ZRBlackColor;
    backView.layer.cornerRadius = 24 * SCREENH6;//裁成圆角
    backView.layer.masksToBounds = YES;//隐藏裁剪掉的部分
    backView.userInteractionEnabled  = NO;
    
    self.backView = backView;
    
    [self.contentView addSubview:self.backView];
    
    UIImageView * imageButton = [UIImageView new];
    
    //  把图片设置成圆形
    imageButton.userInteractionEnabled = NO;
    imageButton.contentMode = UIViewContentModeScaleAspectFit;
    
//    [imageButton addTarget:self action:@selector(changeButtonState) forControlEvents:UIControlEventTouchUpInside];
    
    self.imageButton = imageButton;
    
    [self.backView addSubview:self.imageButton];
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"----";
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    titleLabel.textColor = ZRBlackColor;
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
}


- (void)layoutSubviews{
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.contentView).offset(13 * SCREENH6);
        make.width.height.mas_equalTo(48 * SCREENH6);
    }];
    
    [self.imageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.backView);
        make.centerY.mas_equalTo(self.backView);
        make.width.height.mas_equalTo(25 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.imageButton);
        make.top.mas_equalTo(self.imageButton.mas_bottom).offset(15 * SCREENH6);
    }];
}


- (void)changeButtonState{
    [self.imageButton setBackgroundColor:ColorWithRGB(0xFFF3AE)];
//    NSLog(@"=====%ld",self.tag);
}

@end
